//
//  ST_ShareMyAppController.swift
//  btvideo
//
//  Created by mac on 2020/7/14.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftyUserDefaults

class ST_ShareMyAppController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.addSubview(share_view)
        share_view.snp.makeConstraints { (make) in
            make.height.equalTo(338+BTSafeAreaBottom+16)
            make.bottom.equalToSuperview().offset(16)
            make.left.right.equalToSuperview()
        }
        
        if share_data == nil{
            request_data()
        }
        
    }
    
    
    fileprivate var request_number = 0
    
    fileprivate func request_data(){
         
        if self.request_number > 5{
            return
        }
        
        JVrequest(PH.shareDataInfoApi,parameters: ["accid":Defaults[.currentUserID]] ,success: { (json) in
            
            let shareJson = json["data"]
            
            self.share_data = ST_ShareViewStruct(url: shareJson["share_url"].stringValue, icon: shareJson["icon"].stringValue, title: shareJson["title"].stringValue, content: shareJson["content"].stringValue)
            
            
        }) { (code, err) in
            
            self.request_number += 1
            
            back_thread_execute(afterDelay: 0.2) {
                self.request_data()
            }
        }
    }
    
    
    
    fileprivate lazy var share_view:ST_ShareAppView = {
        let control = ST_ShareAppView()
        return control
    }()

    ///指定分享数据
    var share_data:ST_ShareViewStruct?{
        didSet{
            share_view.share_data = share_data
        }
    }
}
